package com.example.finalproject;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.ArrayList;
import java.util.Map;

public class MyAdapter extends ArrayAdapter {

    private static final String TAG="MyAdapter";

    public MyAdapter(@NonNull Context context, int resource,
                     @NonNull ArrayList<HistoryItem> list) {
        super(context, resource,list);

    }


    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        View itemView = convertView;
        if(itemView == null){
            itemView = LayoutInflater.from(getContext()).inflate(R.layout.layout,
                    parent,
                    false);
        }
        HistoryItem historyItem=(HistoryItem)getItem(position);
        TextView tvdifficulty = (TextView) itemView.findViewById(R.id.textView2);
        TextView tvscore =(TextView) itemView.findViewById(R.id.textView4);
        Log.i(TAG,"tvdifficulty="+historyItem.getDifficulty());
        Log.i(TAG,"tvscore="+historyItem.getScore());
        tvdifficulty.setText(historyItem.getDifficulty());
        tvscore.setText(String.valueOf(historyItem.getScore()));

        return itemView;
    }
}
